package com.sky.controller.admin;

import cn.hutool.core.date.DatePattern;
import com.sky.result.Result;
import com.sky.service.IDateService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @BelongsProject: sky-take-out
 * @Author: XieMingHui
 * @CreateTime: 2023-11-22  07:47
 * @Description: 数据统计接口
 * @Version: 1.0
 */
@RestController
@RequestMapping("/admin/report")
public class DataController {
    @Resource
    private IDateService iDateService;

    /**
     * 导出报表
     * @author: XieMingHui
     * @param: [响应体]
     * @return: 导出成功
     **/
    @GetMapping("/export")
    public Result<String> export(HttpServletResponse response){
        return iDateService.export(response);
    }

    /**
     * 查询销量排名10
     * @author: XieMingHui
     * @param: [统计排名的时间]
     * @return: 返回菜品排名和金额排名字符串的对象
     **/
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> top(
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate  begin,
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate end){
        return iDateService.top(begin,end);
    }

    /**
     * 用户统计
     * @author: XieMingHui
     * @param: []
     * @return:
     **/
    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate  begin,
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate end){
        return iDateService.userStatistics(begin,end);
    }

    /**
     * 营业额统计
     * @author: XieMingHui
     * @param: []
     * @return:
     **/
    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate  begin,
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate end){
        return iDateService.turnoverStatistics(begin,end);
    }

    /**
     * 订单统计
     * @author: XieMingHui
     * @param: []
     * @return:
     **/
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> ordersStatistics(
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate  begin,
            @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN) LocalDate end){
        return iDateService.ordersStatistics(begin,end);
    }
}
